package com.logic.landseaserver.service.bill.offrent;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.apache.commons.lang.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.logic.common.security.SecurityUtils;
import com.logic.landseaserver.common.LandeaConstants;
import com.logic.landseaserver.common.LandseaErrorMessageEnum;
import com.logic.landseaserver.common.enums.BillStatusEnum;
import com.logic.landseaserver.common.enums.BillTypeEnum;
import com.logic.landseaserver.common.enums.ContractStatusCodeEnum;
import com.logic.landseaserver.common.enums.ExpensesStatusEnum;
import com.logic.landseaserver.common.exception.LandseaException;
import com.logic.landseaserver.common.util.ConstantChar;
import com.logic.landseaserver.common.util.DateUtil;
import com.logic.landseaserver.common.util.LandSeaUtil;
import com.logic.landseaserver.domain.Bill;
import com.logic.landseaserver.domain.BillDetail;
import com.logic.landseaserver.domain.Contract;
import com.logic.landseaserver.domain.Expenses;
import com.logic.landseaserver.domain.MonthlyBill;
import com.logic.landseaserver.domain.PreOffrentBill;
import com.logic.landseaserver.domain.PreOffrentDetailBill;
import com.logic.landseaserver.models.prepayment.service.PrepaymentService;
import com.logic.landseaserver.persistence.read.BillDetailReadMapper;
import com.logic.landseaserver.persistence.read.BillReadMapper;
import com.logic.landseaserver.persistence.read.CheckFeeListReadMapper;
import com.logic.landseaserver.persistence.read.ContractReadMapper;
import com.logic.landseaserver.persistence.read.ExpensesReadMapper;
import com.logic.landseaserver.persistence.read.MonthlyBillReadMapper;
import com.logic.landseaserver.persistence.read.PreOffrentBillReadMapper;
import com.logic.landseaserver.persistence.read.PreOffrentDetailBillReadMapper;
import com.logic.landseaserver.persistence.write.PreOffrentBillWriteMapper;
import com.logic.landseaserver.persistence.write.PreOffrentDetailBillWriteMapper;
import com.logic.landseaserver.ws.dto.CheckFeeListDTO;
import com.logic.landseaserver.ws.dto.ContractMonthFeeDTO;
import com.logic.system.service.IConfigurationService;

/**
 * Created by Junny on 2017/8/21.
 */
@Service
public class OffrentPreBillService extends AbstractOffrentPreBill {

    private static final Logger LOG = LoggerFactory.getLogger(OffrentPreBillService.class);
    @Autowired
    private PreOffrentBillReadMapper preOffrentBillReadMapper;

    @Autowired
    private PreOffrentBillWriteMapper preOffrentBillWriteMapper;

    @Autowired
    private PreOffrentDetailBillReadMapper preOffrentDetailBillReadMapper;

    @Autowired
    private PreOffrentDetailBillWriteMapper preOffrentDetailBillWriteMapper;

    @Autowired
    private BillDetailReadMapper billDetailReadMapper;

    @Autowired
    private MonthlyBillReadMapper monthlyBillReadMapper;

    @Autowired
    private BillReadMapper billReadMapper;

    @Autowired
    private CheckFeeListReadMapper checkFeeListReadMapper;

    @Autowired
    private ExpensesReadMapper expensesReadMapper;

    @Autowired
    private ContractReadMapper contractReadMapper;

    @Autowired
    private IConfigurationService configurationService;
    
    @Autowired
    private PrepaymentService prepaymentService;

    @Override
    protected Integer createPreBillDetails(Contract contract, boolean isNeedProcessAccount) throws LandseaException{
        PreBillCondition pbc = new PreBillCondition();
        //退租日期
        Date offrentDate = new Date();
        pbc.setOffrentDate(offrentDate);
        //contract.setLastModifiedDtm(offrentDate);
        List<PreOffrentDetailBill> preOffrentDetailBills = new ArrayList<>();
        List<BillDetail> lastPayBillDts = queryLastPayBillDetail(contract.getId());
        String rentType = contract.getRentType()==null ? "" : contract.getRentType();
        boolean rerentFlag = contract.getOriginalCId()!=null && rentType.equals(LandeaConstants.ReRentType.RERENT);
        int reRentInFlag = DateUtil.compareTime(contract.getInDate(),offrentDate);;
        //获取上次房租服务费缴费日期
        Optional<BillDetail> billHourse = lastPayBillDts.stream().filter(e -> e.getType().equals(BillTypeEnum.CTBI8.getCode())).findFirst();
        if (!billHourse.isPresent()) {
            throw LandseaException.createException(LandseaErrorMessageEnum.OFFRENT_HOURSE_BILL_ERROR);
        }
        Optional<BillDetail>  seriveBill = lastPayBillDts.stream().filter(e -> e.getType().equals(BillTypeEnum.CTBI9.getCode())).findFirst();

        //offFlag =0 则房租物业缴费到合同结束日 offFlag =-1 则房租物业缴费未到合同结束日
        int offFlag= DateUtil.compareTime(offrentDate,contract.getOutDate());
        //判断房租已缴日期是否和合同结束日一致
        int offFlag2= DateUtil.compareTime(contract.getOutDate(),billHourse.get().getDateEnd());
        pbc.setOutOffrentFlag(offFlag);
        pbc.setHourseBillPayFlag(offFlag2);
        //合同日退款 则不处理房租 物业
        PreOffrentDetailBill hoursePre = null;
        PreOffrentDetailBill propertyPre = null;
        pbc.setHouseAmount(0.0);
        pbc.setServiceAmount(0.0);
        //月平均天数
        Double avrMonthDays =  configurationService.getDoubleValue("SYS_MONTHLY_AVA_DAYS");

        //如果是续租合同未到入住日进行退房 B合同未入住 A合同直接变成已结束 费用转B合同
        // B合同退房时获取A合同最后一次交房租\服务费的结束日
        Double haPrice = 0.0;
        Double paPrice = 0.0;
        if(rerentFlag && reRentInFlag>0){
            List<BillDetail> lastPayBillDtsA = queryLastPayBillDetail(contract.getOriginalCId());
            Contract contractA = contractReadMapper.selectByPrimaryKey(contract.getOriginalCId());
            //获取A上次房租服务费缴费日期
            Optional<BillDetail> billHourseA = lastPayBillDtsA.stream().filter(e -> e.getType().equals(BillTypeEnum.CTBI8.getCode())).findFirst();
            if (!billHourse.isPresent()) {
                throw LandseaException.createException(LandseaErrorMessageEnum.OFFRENT_HOURSE_BILL_ERROR);
            }
            Optional<BillDetail> seriveBillA = lastPayBillDtsA.stream().filter(e -> e.getType().equals(BillTypeEnum.CTBI9.getCode())).findFirst();
            PreOffrentDetailBill hoursePreA =new OffrentHourseBillFactory(contractA,billHourseA.get(),avrMonthDays).createBill();
            PreOffrentDetailBill propertyPreA = new OffrentPropertyBillFactory(contractA,seriveBillA.get(),avrMonthDays).createBill();;
            String comments = contractA.getContractNo()+ ConstantChar.sys_over_contract;
            hoursePreA.setComments(comments);
            preOffrentDetailBills.add(hoursePreA);
            propertyPreA.setComments(comments);
            preOffrentDetailBills.add(propertyPreA);
            haPrice = hoursePreA.getBillAmount();
            paPrice = propertyPreA.getBillAmount();
        }

        //非合同日退款 计算应退或应收房租
        //取服务费和房费
        if(offFlag!=0){
        //if(offFlag!=0 && offFlag2!=0){
            hoursePre = new OffrentHourseBillFactory(contract,billHourse.get(),avrMonthDays).createBill();
            if (null == hoursePre) {
                pbc.setLateFee(0.0);
            } else{
                //服务费和房租周期一致
                propertyPre =new OffrentPropertyBillFactory(contract,seriveBill.get(),avrMonthDays).createBill();
                preOffrentDetailBills.add(hoursePre);
                preOffrentDetailBills.add(propertyPre);
                pbc.setHouseAmount(hoursePre.getBillAmount()+haPrice);
                pbc.setServiceAmount(propertyPre.getBillAmount()+paPrice);
            }
        }
        //逾期退房 每天收取滞纳金（房租的x%）
        if(offFlag==1){
            //计算合同日到目前共有x天
            int inDay =  DateUtil.getInstence().differentDaysByMillisecond(contract.getOutDate(),offrentDate)-1;
            //获取滞纳金比例
            //收取滞纳金额百分比
            Double persentage = configurationService.getDoubleValue("SYS_PRO_OF_OVE_FIN");
            if (persentage == null || persentage <= 0) {
                pbc.setLateFee(0.0);
            }else{
                Double lateAmout = LandSeaUtil.get2Double(contract.getSalePrice()*persentage*inDay);
                PreOffrentDetailBill lateFee = new PreOffrentDetailBill();
                lateFee.setPreType(BillTypeEnum.CTBI13.getCode());
                lateFee.setBillAmount(lateAmout);
                lateFee.setDateBegin(DateUtils.addDays(contract.getOutDate(),1));
                lateFee.setDateEnd(offrentDate);
                preOffrentDetailBills.add(lateFee);
                pbc.setLateFee(lateAmout);
            }
        }else{
            pbc.setLateFee(0.0);
        }
        //获取交割单费项记录
        //交割单有哪些类型
        List<String> ckFees = new ArrayList<>();
        List<PreOffrentDetailBill> cfeeLists = checkFeeLists(contract, lastPayBillDts,ckFees);
        //已收款金额
        Double receivedAmount = 0.0;
        //获取未缴的其他费项
        List<MonthlyBill> monthlyBills = queryMonthyNoPayBill(contract,ckFees);
        //查询部分支付的账单
        List<Bill> receivedHalfList = billReadMapper.queryBillForCIdStatus(contract.getId(), BillStatusEnum.BIST1.getCode());
        if (receivedHalfList != null) {
            for (Bill bill : receivedHalfList) {
                receivedAmount = receivedAmount + bill.getAmountReceived();
            }
            receivedAmount = LandSeaUtil.get2Double(receivedAmount);
        }
        //是否存在未缴账单
        List<Bill> noPayList = billReadMapper.queryBillForCIdStatus(contract.getId(), BillStatusEnum.BIST3.getCode());
        if(noPayList!=null || receivedAmount!=0.0){
            pbc.setHasNoPayBill(true);
        }
        pbc.setReceviedAmount(receivedAmount);
        //将未缴其他费项加入至predetailbill
        if(monthlyBills!=null){
            Double monthlyAmount = 0.0;
            for(MonthlyBill monthlyBill:monthlyBills){
                monthlyAmount = monthlyAmount+monthlyBill.getBillPrice();
                PreOffrentDetailBill mdb = new PreOffrentDetailBill();
                mdb.setPreType(monthlyBill.getExpenseType());
                mdb.setConsumption(monthlyBill.getConsumption());
                mdb.setBillAmount(monthlyBill.getBillPrice());
                mdb.setDateBegin(monthlyBill.getStartTime());
                mdb.setDateEnd(monthlyBill.getEndTime());
                preOffrentDetailBills.add(mdb);
            }
            pbc.setMonthlyBillAmount(monthlyAmount);
        }
        //用量 水->金额
      //  Double waterAmount = 0.0;
        //将交割单加入至predetailbill
        if(cfeeLists!=null){
            Double checkFeeAmount=0.0;
            for(PreOffrentDetailBill pdb:cfeeLists){
                checkFeeAmount= checkFeeAmount+pdb.getBillAmount();
                preOffrentDetailBills.add(pdb);
            }
            pbc.setCheckFeesAmount(checkFeeAmount);
        }
        
        if (isNeedProcessAccount)
        {
            // 处理账户余额，续租的A合同不存在手动退租情况
            prepaymentService.offrentProcessAccount(preOffrentDetailBills, contract);
        }
        
        int preBillId = createPreBill(preOffrentDetailBills,contract,lastPayBillDts,pbc);
        for(PreOffrentDetailBill pdb:preOffrentDetailBills){
            pdb.setPrebillId(preBillId);
            pdb.setCouponFlag(false);
            pdb.updateCommonInfo(SecurityUtils.getCurrentLogin().getUserId());
        }
        preOffrentDetailBillWriteMapper.insertList(preOffrentDetailBills);
        
        return preBillId;
    }

    private Integer createPreBill(List<PreOffrentDetailBill> preOffrentDetailBills,Contract contract,
                               List<BillDetail> lastPayBillDts,PreBillCondition pbc){
        //退租日期
        Date offrentDate = new Date();
        Double totalAmount=0.0;
        //获取水费押金
        Double waterDpsAmount = getWaterDeposit(preOffrentDetailBills, contract);
        //房屋押金
        Double hourseDpsAmount = getHourseDeposit(preOffrentDetailBills, contract, lastPayBillDts);
        if(preOffrentDetailBills!=null){
            for(PreOffrentDetailBill pod:preOffrentDetailBills){
                totalAmount = totalAmount+pod.getBillAmount();
                pod.updateCommonInfo(SecurityUtils.getCurrentLogin().getUserId());
            }
            totalAmount = LandSeaUtil.get2Double(totalAmount);
        }
        //剩余水费押金
       /* Optional<BillDetail> waterUsedBill = lastPayBillDts.stream().filter(e -> e.getType().equals(BillTypeEnum.CTBI1.getCode())).findFirst();
        if (waterUsedBill.isPresent()) {
            waterDpsAmount =LandSeaUtil.get2Double(waterDpsAmount-waterUsedBill.get().getMoney());
        }*/
        //是否合同到期退
        int offFlag= DateUtil.compareTime(offrentDate,contract.getOutDate());
        //违约金
        Double damagesAmount=0.0;
        //合同日退房
        PreOffrentBill preBill = new PreOffrentBill();
        preBill.setContractId(contract.getId());
        preBill.setContractNo(contract.getContractNo());
        preBill.setBillMonth(DateUtil.getInstence().convertYM(new Date()));
        //正常退房
        Double refundAmount = 0.0;
        if(pbc.getOutOffrentFlag()==0 && pbc.getHourseBillPayFlag()==0){
            refundAmount =totalAmount;
            preBill.setOffrentType(LandeaConstants.OffrentType.NORMAL);//正常退房
            preBill.setDepositFlag(true);
        }else{
            //剩余房租+服务费
            Double hsAamount = LandSeaUtil.get2Double(pbc.getHouseAmount()+pbc.getServiceAmount());
            //其余费项+交割单费项
            Double otherFees =  LandSeaUtil.get2Double(pbc.getMonthlyBillAmount()+pbc.getCheckFeesAmount()+pbc.getLateFee());
            //合同期内，提前退房
            if(pbc.getHourseBillPayFlag()==0){//房租已缴费至合同结束日
                Double haveAamout = -(hsAamount);
                int btwFlag =haveAamout.compareTo(hourseDpsAmount);
                if(btwFlag>0){//剩余房租、服务费>房屋押金
                    refundAmount = hsAamount+waterDpsAmount+otherFees;
                    damagesAmount = hourseDpsAmount;
                    preBill.setDepositFlag(false);
                    preBill.setOffrentType(LandeaConstants.OffrentType.BREAK);//违约退房
                }else{
                    //房屋押金+水押金-（其余费项）
                    refundAmount= hourseDpsAmount+waterDpsAmount+otherFees;
                    damagesAmount = hsAamount;
                    preBill.setDepositFlag(true);
                    preBill.setOffrentType(LandeaConstants.OffrentType.ADVANCE);//提前退房
                }
                if(pbc.getOutOffrentFlag()==1){
                    preBill.setOffrentType(LandeaConstants.OffrentType.DELAY);//逾期退房
                    damagesAmount = 0.0;
                }
            }else{//房租未缴费至合同结束日
                preBill.setOffrentType(LandeaConstants.OffrentType.BREAK);//违约退房
                //剩余房租+水费押金-其余费用
                refundAmount = hsAamount+waterDpsAmount+otherFees;
                damagesAmount = hourseDpsAmount;
                preBill.setDepositFlag(false);
            }
        }
        //违约金
        Double damafesAmout=Math.abs(LandSeaUtil.get2Double(damagesAmount));
        if(damagesAmount!=0.0){
            PreOffrentDetailBill damagesBill = new PreOffrentDetailBill();
            damagesBill.setDateBegin(contract.getInDate());
            damagesBill.setDateEnd(new Date());
            damagesBill.setBillAmount(damafesAmout);
            damagesBill.setPreType(BillTypeEnum.CTBI14.getCode());
            preOffrentDetailBills.add(damagesBill);
        }
        Double recevieMoney = -pbc.getReceviedAmount();
        //已收金额
        if(recevieMoney!=0.0){
            PreOffrentDetailBill reciveBill = new PreOffrentDetailBill();
            reciveBill.setDateBegin(new Date());
            reciveBill.setDateEnd(new Date());
            reciveBill.setBillAmount(recevieMoney);
            reciveBill.setPreType(BillTypeEnum.CTBI23.getCode());
            preOffrentDetailBills.add(reciveBill);
        }
        preBill.setRefundAmount(LandSeaUtil.get2Double(totalAmount+damafesAmout+recevieMoney));
        preBill.setDamagesAmount(damafesAmout);
        preBill.updateCommonInfo(SecurityUtils.getCurrentLogin().getUserId());
        preOffrentBillWriteMapper.insertSelective(preBill);
        return preBill.getId();
    }

    private Double getWaterDeposit(List<PreOffrentDetailBill> preOffrentDetailBills, Contract contract) {
        Double waterDepositFee = -contract.getWaterDeposit();
       // Optional<BillDetail> waterBill = lastPayBillDts.stream().filter(e -> e.getType().equals(BillTypeEnum.CTBI10.getCode())).findFirst();
       // if (waterBill.isPresent()) {
          //  waterDepositFee=-waterDepositFee;
            PreOffrentDetailBill waterDeposit = new PreOffrentDetailBill();
            waterDeposit.setDateBegin(contract.getInDate());
            waterDeposit.setDateEnd(contract.getOutDate());
            waterDeposit.setBillAmount(waterDepositFee);
            waterDeposit.setPreType(BillTypeEnum.CTBI10.getCode());
            preOffrentDetailBills.add(waterDeposit);
       // }
        return waterDepositFee;
    }

    //房屋押金
    private Double getHourseDeposit(List<PreOffrentDetailBill> preOffrentDetailBills, Contract contract, List<BillDetail> lastPayBillDts) {
        Double hourseDepositFee = 0.0;
        Optional<BillDetail> hourseDpsBill = lastPayBillDts.stream().filter(e -> e.getType().equals(BillTypeEnum.CTBI11.getCode())).findFirst();
        if (hourseDpsBill.isPresent()) {
            hourseDepositFee = hourseDpsBill.get().getMoney();
            PreOffrentDetailBill hourseDeposit = new PreOffrentDetailBill();
            hourseDeposit.setDateBegin(contract.getInDate());
            hourseDeposit.setDateEnd(contract.getOutDate());
            hourseDeposit.setBillAmount(-hourseDepositFee);
            hourseDeposit.setPreType(BillTypeEnum.CTBI11.getCode());
            preOffrentDetailBills.add(hourseDeposit);
        }
        return hourseDepositFee;
    }

    @Override
    protected PreOffrentBill queryPreBill(Integer contractId) {
        return preOffrentBillReadMapper.queryByContractId(contractId);
    }

    @Override
    protected void deletePreBill(Integer preBillId) {
        //删除子项
        preOffrentDetailBillWriteMapper.deleteByPreBillId(preBillId);
        preOffrentBillWriteMapper.deleteByPrimaryKey(preBillId);
    }

    @Override
    protected boolean cancelPreBillById(Integer preBillId) {
        //删除子项
        PreOffrentBill record =new PreOffrentBill();
        record.setId(preBillId);
        record.setDeleted(true);
        record.updateCommonInfo(SecurityUtils.getCurrentLogin().getUserId());
        preOffrentBillWriteMapper.updateByPrimaryKeySelective(record);
        preOffrentDetailBillWriteMapper.cancleByPreBillId(preBillId);
        return true;
    }

    @Override
    protected List<BillDetail> queryLastPayBillDetail(int contractId) {
        //取出该合同缴费过的所有类型
        List<String> feeTypes = billDetailReadMapper.queryFeeTypeByContract(contractId);
        //取出上一次缴费记录
        HashMap queryMap = new HashMap();
        queryMap.put("types", feeTypes);
        queryMap.put("contractId", contractId);
        queryMap.put("payFlag", true);
        return billDetailReadMapper.queryLastBillType(queryMap);
    }

    @Override
    protected List<PreOffrentDetailBill> checkFeeLists(Contract contract, List<BillDetail> billDetails, List<String> ckFees)throws LandseaException {
        List<PreOffrentDetailBill> preBillDetails= new ArrayList<>();
        //计量类
        Map<String,Object> queryParam = new HashMap<String,Object>();
        queryParam.put("contractId", contract.getId());
        queryParam.put("checkType", 2);
        List<CheckFeeListDTO> feeOutList = checkFeeListReadMapper.selectByContractIdAndCheckType(queryParam);
        queryParam.put("checkType", 1);
        List<CheckFeeListDTO> feeInList = checkFeeListReadMapper.selectByContractIdAndCheckType(queryParam);
        if(feeInList==null){
            throw LandseaException.createException(LandseaErrorMessageEnum.OFFRENT_CHECKIN_FEELIST_ERROR);
        }
        List<ContractMonthFeeDTO> contractMonthFees = contractReadMapper.queryContractFee(contract.getId(), ContractStatusCodeEnum.SIGN.getCode());
        ContractMonthFeeDTO contractMonthFeeDTO = null;
        if(contractMonthFees.size()>0){
            contractMonthFeeDTO = contractMonthFees.get(0);
        }
        //获取计量类上次抄表日期
        if(feeOutList!=null){
            for(CheckFeeListDTO fee:feeOutList){
                String type= fee.getType();
                ckFees.add(type);
                Optional<BillDetail> billDt =billDetails.stream().filter(e -> e.getType().equals(type)).findFirst();
                Expenses lastEx= null;
                String feeStartTime = null;
                PreOffrentDetailBill preDetail = new PreOffrentDetailBill();
                if(billDt.isPresent()){//有交过计量类数据 从运营数据中获取
                    feeStartTime=DateUtil.getInstence().convertDate(billDt.get().getDateEnd());
                    HashMap qMap=new HashMap();
                    qMap.put("roomId",contract.getRoomId());
                    qMap.put("status", ExpensesStatusEnum.ES3.getCode());
                    qMap.put("type",type);
                    qMap.put("inDate",feeStartTime);
                    lastEx = expensesReadMapper.querExpenses(qMap);
                    preDetail.setDateBegin(DateUtils.addDays(DateUtil.getInstence().convertDate(feeStartTime),1));
                }else{//从入住交割单获取信息
                    Optional<CheckFeeListDTO> inFee =feeInList.stream().filter(e -> e.getType().equals(type)).findFirst();
                    if(inFee.isPresent()){
                        feeStartTime = DateUtil.getInstence().convertDate(inFee.get().getInDate());
                        lastEx = new Expenses();
                        lastEx.setDegree(inFee.get().getConsumptionEnd());
                        preDetail.setDateBegin(DateUtil.getInstence().convertDate(feeStartTime));
                    }
                }
                if(lastEx!=null){
                    preDetail.setDateEnd(fee.getInDate());
                    preDetail.setPreType(type);
                    Double consum =LandSeaUtil.get2Double(fee.getConsumptionEnd()-lastEx.getDegree());
                    preDetail.setConsumption(consum);
                    preDetail.setBillAmount(calculationPrice(type,contractMonthFeeDTO,consum));
                    preBillDetails.add(preDetail);
                }else{
                    LOG.info("has not query last exp indata,contract id is "+contract.getId()+" fee type is :"+type);
                    continue;
                }
            }
        }else{
            throw LandseaException.createException(LandseaErrorMessageEnum.CONTRACT_IS_NULL);
        }
        return preBillDetails;
    }

    @Override
    protected List<MonthlyBill> queryMonthyNoPayBill(Contract contract, List<String> ckFees) {
        //退租处理的账单月
        String monthBill = DateUtil.getInstence().convertYM(new Date());
        //退房时获取管家店长录入的未缴其余费项
        List<MonthlyBill> monthlyBills = new ArrayList<>();
        List<MonthlyBill> mthBills = monthlyBillReadMapper.queryMonthlyBillByStatus(contract.getId(), BillStatusEnum.BIST3.getCode());
        if(mthBills!=null){
           /* String[] feeTypes = {BillTypeEnum.CTBI1.getCode(), BillTypeEnum.CTBI2.getCode(), BillTypeEnum.CTBI3.getCode(),
                    BillTypeEnum.CTBI4.getCode()};*/
            Boolean checked  =  ckFees.size()>0 ? true :false;
            for(MonthlyBill bill:mthBills){
                //排除计量类的
                if(checked){
                    if(ckFees.contains(bill.getExpenseType())){
                        continue;
                    }
                }
                monthlyBills.add(bill);
            }
        }

        return monthlyBills;
    }

    @Override
    protected List<PreOffrentDetailBill> queryPreOffDetails(Integer preBillId,String billType) {
        return preOffrentDetailBillReadMapper.queryDetailByPreId(preBillId,billType);
    }

    private Double calculationPrice(String feeType, ContractMonthFeeDTO cmDto, Double consumption){
        Double billPrice = 0.0;
        //计算水
        if(feeType.equals(BillTypeEnum.CTBI1.getCode())){
            return LandSeaUtil.get2Double(consumption*cmDto.getWaterPrice());
        }else if(feeType.equals(BillTypeEnum.CTBI2.getCode())){
            return LandSeaUtil.get2Double(consumption*cmDto.getElectricPrice());
        }else if(feeType.equals(BillTypeEnum.CTBI3.getCode())){
            return LandSeaUtil.get2Double(consumption*cmDto.getGasPrice());
        }else if(feeType.equals(BillTypeEnum.CTBI4.getCode())){
            return  LandSeaUtil.get2Double(consumption*cmDto.getHotWaterPrice());
        }else{
            return billPrice;
        }
    }
}
